/*
 * @Description: 添加公告
 * @Author: Zzt
 * @Date: 2023-02-20 16:12:54
 * @LastEditTime: 2023-02-28 11:26:21
 */
import JPModal from '@/components/JPComponents/JPModal';
import { ICommonDialog } from '@/interfaces/global';
import { Button, Form } from 'antd';
import { useEffect, useState } from 'react';
import { useAnnouncementMgtContext } from '../../contexts/AnnouncementMgtContext';
import AnnounceForm from './AnnounceForm';

const AddAnnounce = (props: ICommonDialog) => {
  const { addAnnounceList } = useAnnouncementMgtContext();
  const [form] = Form.useForm();
  const { visible, onClose } = props;

  useEffect(() => {
    form.resetFields();
  }, [visible]);

  const onFinish = (values: any) => {
    addAnnounceList(values).then(onClose());
    console.log('values', { ...values, status: 1 });
  };
  return (
    <>
      <JPModal
        visible={visible}
        onCancel={onClose}
        // draggable={true}
        title="新建公告"
        width={600}
        footer={[
          <Button key={'close'} onClick={() => onClose()}>
            取消
          </Button>,
          <Button key={'submit'} type="primary" onClick={() => form.submit()}>
            保存
          </Button>
        ]}
      >
        <Form form={form} onFinish={onFinish} labelCol={{ span: 4 }} wrapperCol={{ span: 20 }}>
          <AnnounceForm view={false} />
        </Form>
      </JPModal>
    </>
  );
};
export default AddAnnounce;
